﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Wicresoft.SMS.Web.App_GlobalResources;
namespace Wicresoft.SMS.Web.Models
{
    [AuthoriseImplement(typeof(OnlyCheckEnableImpIAuthorise))]
    public class UserSetting : BaseModelWithAuthorise
    {
        [AuthoriseImplement(typeof(OnlyCheckVisibleImpIAuthorise))] //this AuthoriseImplement will override the AuthoriseImplement in class
        [AuthoriseFlag(AuthoriseFlag.page_sms_send)]
        [DisplayName("Send SMS(from Model Attribute)")]                 //indicate the display of the link
        public string link_sendsms { get; set; }                                       //the value itself will olny be used as linkText if no display attribute

        [AuthoriseImplement(typeof(OnlyCheckVisibleImpIAuthorise))]
        [AuthoriseFlag(AuthoriseFlag.page_sms_template)]
        public string link_smstemplate { get; set; }


        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_alias)]      //edit_home_setting_alias is disabled in the page
        [AuthoriseControlType(Web.ControlType.text)]                //a text element will be rendered
        public string Alias { get; set; }                                           //because no display attribute here , so the value of property itself will be rendered as display

        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_displayname)]    //edit_home_setting_alias is enabled in the page
        [AuthoriseControlType(Web.ControlType.text)]
        public string DisplayName { get; set; }

        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_pwd)]
        [AuthoriseControlType(Web.ControlType.password)]    //password element will be rendered
        public string Password { get; set; }


        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_displayname)]
        [AuthoriseControlType(Web.ControlType.checkbox)]        //checkbox element will be rendered
        [DisplayName("Checked?")]
        public bool IsAdmin { get; set; }                           //the value true/false will influence the initial check state of the checkbox


        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_alias)]
        [AuthoriseControlType(Web.ControlType.radio)]           //radio element will be rendered
        [DisplayName("radio1")]
        public bool IsRadio1 { get; set; }


        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_alias)]
        [AuthoriseControlType(Web.ControlType.radio)]
        [DisplayName("radio2")]
        public bool IsRadio2 { get; set; }


        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_displayname)]  //disabled
        [AuthoriseControlType(Web.ControlType.textarea)]    //textarea element will be rendered
        public string TextArea { get; set; }


        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_displayname)]
        [AuthoriseControlType(Web.ControlType.multi_select)]    //listbox will be rendered
        //the choose of user will be post back and we want to get them in the property public int[] selected { get; set; }
        //make sure that the Value you indicate in SelectListItem has a same type of "selected's item"
        [PostbackBinding(BindingPropertyName = "selected")]       
        public IEnumerable<SelectListItem> selector { get; set; }
        //get the post back data by selector
        public int[] selected { get; set; }


        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_alias)]
        [AuthoriseControlType(Web.ControlType.button)]  //rendered a common button
        [DisplayName("普通按钮，没有全球化")]
        public string Button { get; set; }

        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_pwd)]
        [AuthoriseControlType(Web.ControlType.submit)] //rendered a submit button , which will cause submit
        [Display(Name="test_string" , ResourceType=typeof(Resources))]  //we can apply localization like this
        public string Submit { get; set; }
    }

    public class SelectorItem
    {
        public int ValueInt { get; set; }
        public string DisplayString { get; set; }
    }

}